/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.core.job;

import cn.hutool.core.date.DateUnit;
import cn.hutool.cron.pattern.CronPatternBuilder;
import cn.hutool.cron.pattern.Part;
import info.peigen.hotpot.component.schedule.core.repository.service.ScheduleNodeRepository;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleExecuteResult;
import info.peigen.hotpot.component.schedule.facade.enums.ScheduleCommunicationMethod;
import info.peigen.hotpot.component.schedule.facade.job.ScheduleFacadeJob;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(ScheduleNodeUpdateJob)</b>
 * 自动更新当前节点是否可用 Job
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/12/29
 */
@Slf4j
@Component
public class ScheduleNodeUpdateJob implements ScheduleFacadeJob {
    @Inject
    private ScheduleNodeRepository scheduleNodeRepository;

    @Override
    public String jobName() {
        return "更新节点Job";
    }

    @Override
    public CronPatternBuilder cron() {
        return CronPatternBuilder.of()
                .set(Part.MINUTE, "0/" + 5);
        // .set(Part.SECOND, "0/5");
    }

    @Override
    public ScheduleCommunicationMethod method() {
        return ScheduleCommunicationMethod.Bean;
    }

    @Override
    public String urlOrEndPoint() {
        return "";
    }

    @Override
    public int executeTimeout() {
        return 0;
    }

    @Override
    public int executeFailRetryCount() {
        return 0;
    }

    @Override
    public ScheduleExecuteResult execute() {
        log.debug("ScheduleNodeUpdateJob执行");
        scheduleNodeRepository.offlineNode(DateUnit.MINUTE, 5L);
        return null;
    }
}